/*
 * MainMenuView.cpp
 *
 *  Created on: 2011-5-6
 *      Author: Administrator
 */

#include <FMedia.h>
#include <FApp.h>
#include "MainMenuView.h"

using namespace Osp::App;
using namespace Osp::Graphics;
using namespace Osp::Media;
using namespace Osp::Ui;
using namespace Osp::Ui::Controls;

namespace Galaxy {

MainMenuView::MainMenuView(IHandleMenuEvent* pMenuEventHandler){
	__pMenuEventHandler = pMenuEventHandler;
}

MainMenuView::~MainMenuView() {
}

bool MainMenuView::Initialize() {
	Form::Construct(Osp::Ui::Controls::FORM_STYLE_NORMAL);

	Rectangle size(100,100, 280, 50);
	Button* tutorialButton = new Button();
	tutorialButton->Construct(size,L"Tutorial");
	tutorialButton->SetActionId(BUTTON_ACTION_TUTORIAL);
	tutorialButton->AddActionEventListener(*this);

	size.Translate(0, 60);
	Button* campaignButton = new Button();
	campaignButton->Construct(size, L"Campaign");
	campaignButton->SetActionId(BUTTON_ACTION_CAMPAIGN);
	campaignButton->AddActionEventListener(*this);

	size.Translate(0, 60);
	Button* randomFightButton = new Button();
	randomFightButton->Construct(size, L"Random Fight");
	randomFightButton->SetActionId(BUTTON_ACTION_RANFIGHT);
	randomFightButton->AddActionEventListener(*this);

	size.Translate(0, 60);
	Button* team2v2Button = new Button();
	team2v2Button->Construct(size, L"Team 2 VS 2");
	team2v2Button->SetActionId(BUTTON_ACTION_TEAM2VS2);
	team2v2Button->AddActionEventListener(*this);

	size.Translate(0, 60);
	Button* optionsButton = new Button();
	optionsButton->Construct(size, L"Options");
	optionsButton->SetActionId(BUTTON_ACTION_OPTIONS);
	optionsButton->AddActionEventListener(*this);

	size.Translate(0, 60);
	Button* resetButton = new Button();
	resetButton->Construct(size, L"Reset Stats");
	resetButton->SetActionId(BUTTON_ACTION_RESET);
	resetButton->AddActionEventListener(*this);

	AddControl(*tutorialButton);
	AddControl(*campaignButton);
	AddControl(*randomFightButton);
	AddControl(*team2v2Button);
	AddControl(*optionsButton);
	AddControl(*resetButton);

	return true;
}

result MainMenuView::OnInitializing(void) {
	result r = E_SUCCESS;

	Image decoder;
	decoder.Construct();
	__pBackgroundBitmap = decoder.DecodeN(L"/Home/nebula2.png",Osp::Graphics::BITMAP_PIXEL_FORMAT_ARGB8888);
	if(__pBackgroundBitmap){
		AppLog("__pBackgroundBitmap is null");
	}

	return r;
}

result MainMenuView::OnTerminating(void) {
	result r = E_SUCCESS;


	return r;
}


result MainMenuView::OnDraw(){
	result r = E_SUCCESS;

	Canvas* pCanvas = GetCanvasN();
	if(pCanvas && __pBackgroundBitmap){
		pCanvas->DrawBitmap(Point(0,0), *__pBackgroundBitmap);
	}

	return r;
}

void MainMenuView::OnActionPerformed(const Osp::Ui::Control& source, int actionId) {
	if(__pMenuEventHandler){
		__pMenuEventHandler->HandleButtonEvent(source, actionId);
	}
}
}
